package com.link.base.core.basic.properties;

import com.link.base.base.urlinfo.service.UrlInfoService;
import com.link.core.basic.thread.LinkThreadPoolExecutor;
import com.link.core.cllog.LCLogger;
import com.link.core.util.BeanTools;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@Order
public class InitDefaultUrlToRedis  implements ApplicationRunner {
    private static final Logger logger = LogManager.getLogger(InitDefaultUrlToRedis.class);

    @Resource
    private LinkThreadPoolExecutor linkThreadPoolExecutor;


    @Override
    public void run(ApplicationArguments args) {

        //通过线程池执行初始化url信息的动作 HuangLJ 2019年07月26日
        linkThreadPoolExecutor.execute(() -> {
            try {
                //初始化默认url信息
                logger.info("新线程设置url缓存信息。不影响正常访问。");
                UrlInfoService urlInfoService = (UrlInfoService) BeanTools.getBean(UrlInfoService.class);
                urlInfoService.loadUrlToRedis();
                logger.info("新线程设置url缓存信息完成！");
            } catch (Exception e) {
                LCLogger.withException(e);
            }
        });


    }


}
